/// ===========================================================================
/// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
/// KIND, WHETHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
/// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
/// PURPOSE.
/// ===========================================================================
/// 
/// Project:        MOSS Faceted Search
/// Author:         Leonid Lyublinski (leonidly@microsoft.com)
/// Company:        Microsoft Services
/// Date:           05/04/2007  Version:        1.0
///
/// ===========================================================================

using System;
using System.IO;
using System.Reflection;
using System.Text.RegularExpressions;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml;
using System.Xml.XPath;
using System.Xml.Xsl;
using System.Xml.Serialization;
using System.Data;
using Microsoft.SharePoint.WebPartPages;
using Microsoft.Office.Server;
using Microsoft.Office.Server.Search.Query;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;

namespace Microsoft.SharePoint.Portal.ExtendedSearch.Common
{
    public sealed class Cache
    {
        public static string WriteToCache(DataTable dt)
        {
            string result;
            using (StringWriter sw = new StringWriter())
            {
                dt.WriteXml(sw,XmlWriteMode.WriteSchema);
                result = sw.ToString();
            }
            return result;
        }

        private static string MemoryStreamToXMLString(MemoryStream m) 
        { 
            XmlTextReader reader = new XmlTextReader(m); 
            StringBuilder sb = new StringBuilder(); 
            while (reader.Read()) 
            { 
                sb.Append(reader.ReadOuterXml()); 
            } 
            reader.Close(); 
            return sb.ToString(); 
        }
        
        public static DataTable ReadFromCache(string s)
        {
            //XmlTextReader reader = new XmlTextReader();
            StringReader sr = new StringReader(s);
            DataTable dt = new DataTable();
            DataSet ds = new DataSet();
            ds.ReadXml(sr);
            dt = ds.Tables[0];
            
            //MemoryStream ms = new MemoryStream(); 
            //byte[] data = Encoding.Unicode.GetBytes(s); 
            //ms.Write(data, 0, data.Length); 
            //ms.Position = 0;
            //dt.ReadXmlreader); 
            return dt;
        }
    }
}
